<template>
	<view class="page">
		<u-navbar title="成长碎片" border @leftClick="$utils.back()" placeholder />
		<view class="body">
			<z-paging ref="paging" style="height: 100%;" :fixed="false" v-model="data" @query="query"
				:default-page-no="1" :default-page-size="10" @scroll='scroll'>
				<active :list='data' :loading='loading' ref='active' :playIndex='playIndex'
					@reload='$refs.paging.reload()' @ListloadingChange='loading!=loading' />
			</z-paging>
		</view>
		<view class="add" @click="jumpAdd">
			<u-icon color='#fff' name='camera' size='50rpx' />
		</view>
		<view>
			<selectWish :show='show' @close='show=false'/>
		</view>
	</view>
</template>

<script>
	import active from './components/active'
	import selectWish from './components/selectWish'
	export default {
		components: {
			active,
			selectWish
		},
		data() {
			return {
				show:false,
				playIndex: 0,
				data: [],
				loading: true,
			}
		},
		methods: {
			jumpAdd(){
				this.show=true
			},
			scroll(e) {
				let index = 0
				let domTop0 = 0
				const query = uni.createSelectorQuery().in(this.$refs.active);
				query.selectAll('.activeBox').boundingClientRect(data => {
					data.forEach((rect, domIndex) => {
						let domTop = rect.top + top
						if (domIndex == 0) {
							domTop0 = domTop
						}
						if (top > (domTop - domTop0)) {
							index = domIndex
						}
						if (domIndex == data.length - 1) {
							this.playIndex = index

						}
					});
				}).exec();
			},
			query(page, size) {
				let obj = {
					page,
					size
				}
				uni.showLoading({
					title: '加载中...'
				})
				this.$api.My.Fragment(obj).then(res => {
					uni.hideLoading()
					this.$refs.paging.complete(res.data.fragments.data.map(item => {
						return {
							...item,
							user: res.data.users[item.user_id]
						}
					}))
					this.loading = false
				}).catch(err => {
					uni.hideLoading()
					uni.$u.toast(err.data.message)
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		padding: 0rpx 20rpx;
		height: 100vh;
		padding-bottom: calc(constant(safe-area-inset-bottom) + 10rpx);
		/* 兼容 iOS 设备 */
		padding-bottom: calc(env(safe-area-inset-bottom) + 10rpx);
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
	}

	.body {
		margin-top: 20rpx ;
		flex: 1;
		overflow: hidden;
	}
	.add {
		position: fixed;
		right: 5vw;
		bottom: 20vh;
		border-radius: 100%;
		box-shadow: 0 0 10rpx #ddd;
		background: rgba(0, 0, 0, 0.3);
		padding: 20rpx;
		z-index: 2;
	
	}
</style>